<template>
  <view  v-if="template">
    <!-- <image
      :src="${sheep.$url.cdn('/uploads/20240119/9c15ffd192176898bd6814510b128de2.png')"
      mode="scaleToFill"
    /> -->
   
    <s-layout
      title="拼冻网"
      navbar="custom"
      tabbar="/pages/index/index" 
      :bgStyle="template.style?.background"
      :navbarStyle="template.style?.navbar"
      :onShareAppMessage="state.oneshareinfo" 
      headBg = '#FD4F2D'
    >
    <!-- :onShareAppMessage="shareinfo" -->
    <!-- <image :src="sheep.$url.cdn('/uploads/20240119/9c15ffd192176898bd6814510b128de2.png')" class="bg"></image> -->
    <image :src="sheep.$url.cdn(template.data[2].style.background.bgImage)" class="bg"></image>
      <s-block v-for="(item, index) in template.data" :key="index" :styles="item.style">
        <s-block-item :type="item.type" :data="item.data" :styles="item.style" path='index'  />
      </s-block>
      <!-- 广告模块 -->

      <s-popup-image />
    </s-layout>
  </view>
</template>

<script setup>
  import { computed,reactive } from 'vue';
  import { onLoad, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
  import sheep from '@/sheep';
  import $share from '@/sheep/platform/share';
 // #ifdef MP-WEIXIN
  import { onShareTimeline,onShareAppMessage } from '@dcloudio/uni-app';
import share from '@/sheep/platform/share';
    // #endif
  // 隐藏原生tabBar
  uni.hideTabBar();
  const state = reactive({
    shareinfo:{},
    oneshareinfo:{}
  })
  const template = computed(() => sheep.$store('app').template?.home);
  // console.log(template.style)
  onLoad((options) => {
    getshare()
    // #ifdef MP
    // 小程序识别二维码
    if (options.scene) {
      const sceneParams = decodeURIComponent(options.scene).split('=');
      options[sceneParams[0]] = sceneParams[1];
    }
    // #endif

    // 预览模板
    if (options.templateId) {
      sheep.$store('app').init(options.templateId);
    }

    // 解析分享信息
    if (options.spm) {
      $share.decryptSpm(options.spm);
    }

    // 进入指定页面(完整页面路径)
    if (options.page) {
      sheep.$router.go(decodeURIComponent(options.page));
    }
    
    
  });
  async function getshare(){
    const res = await sheep.$api.goods.getShaseData({
        type:'index'
    });
    // console.log("76行") 
    state.shareinfo = res.data
    state.oneshareinfo = res.data
  }

  // 下拉刷新
  onPullDownRefresh(() => {
    sheep.$store('app').init();
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 800);
  });
   // #ifdef MP-WEIXIN
  // 微信小程序分享
  onShareTimeline(() => {
    return {
      title:state.shareinfo.title||'拼冻网',
      path: state.shareinfo.path||'/pages/index/index',
      imageUrl: state.shareinfo.image,
    };
  });
  // onShareAppMessage(() => {
  //   console.log(state.shareinfo.image)
  //   return {
  //     title:state.shareinfo.title||'拼冻网',
  //     path: state.shareinfo.path||'/pages/index/index',
  //     imageUrl: state.shareinfo.image,
  //   };
  // });
  // #endif

  onPageScroll(() => {});
</script>

<style>
.bg{
  position: absolute;
  width: 100%;
  height: 800rpx;
  top: 0rpx;
}
</style>
